Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Graphics /
Chapter 5 - Bitmap Shapes / Using Bitmap Shapes


Editing Part of a Bitmap

QuickDraw GX provides two functions that allow you to manipulate part of a bitmap. The GXGetBitmapParts function copies a rectangular subsection from one bitmap to a new bitmap, and the GXSetBitmapParts function replaces a rectangular subsection of one bitmap with another bitmap.

To extract part of a bitmap shape, you need to declare a reference to a new bitmap shape to hold the extracted part:

gxShape extractedBitmap;
You also need to specify what part of the bitmap to extract. QuickDraw GX provides the gxLongRectangle sturcture for this purpose:

gxLongRectangle extractedBounds = {70, 70, 125, 125};
You can then use the GXGetBitmapParts function to extract the specified section. For example, the following call extracts from the bitmap referenced by the aBitmapShape variable the section starting at 70 pixels over and 70 pixels down and ending at 125 pixels over and 125 pixels down.

extractedBitmap = GXGetBitmapParts(aBitmapShape, 
                                   &extractedBounds);
Applying this function call to the bitmap shown in Figure 5-29 results in the bitmap shown in Figure 5-30.

Figure 5-30 An extracted bitmap

You can use the GXSetBitmapParts function to replace a section of one bitmap with the contents of another bitmap.

For example, you might create a small, square bitmap containing all black pixels:

gxShape insertionBitmap;
gxRectangle insertionGeometry = {ff(0), ff(0), ff(100), ff(100)};

insertionBitmap = GXNewRectangle(&insertionGeometry);
GXSetShapeType(insertionBitmap, gxBitmapType);
Then you can insert that bitmap into the bitmap from Figure 5-29 by specifying where it should be inserted with the declaration

gxLongRectangle whereToInsert = {70, 70, 125, 125};
and then inserting it with this call to the GXSetBitmapParts function:

GXSetBitmapParts(aBitmapShape, &whereToInsert, insertionBitmap);
Notice that the insertionBitmap shape is larger than the whereToInsert rectangle. QuickDraw GX only inserts as much of the insertionBitmap shape as fits in the whereToInsert rectangle, starting with the upper-left corner of the insertionBitmap shape.

The resulting bitmap is shown in Figure 5-31.

Figure 5-31 An edited bitmap

For more information about the GXGetBitmapParts and the GXSetBitmapParts functions, see page 5-74 and page 5-75, respectively.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996